﻿
using System.Collections.Generic;
using System.Linq;
using MiniWeb.Core.Dtos;
using MiniWeb.Core.Entities;
using MiniWeb.Dao;
using MiniWeb.Core.Entities;
using WFramework.MvcPager;

namespace MiniWeb.Task
{
    public class ProductsClassTask
    {
        private readonly ProductsClassDao _dao = new ProductsClassDao();
        private readonly ProductsTypeDao _typedao = new ProductsTypeDao();

        public PagedList<ProductsClass> GetPagedList(int? tid, int pageIndex, int pageSize)
        {
            return _dao.GetPagedList(tid, pageIndex, pageSize);
        }

        public List<ProductsTypesDto> GetClass()
        {
            //商品类目
            var typelist = from tid in _typedao.GetAll(100, null, "Sort ASC")
                           select new ProductsTypesDto
                           {
                               TypeInfo = tid,
                               ClassList = _dao.GetListByTID(tid.ID),
                           };
            return typelist.ToList();
        }

        public ProductsClass GetById(int id)
        {
            return _dao.GetById(id);
        }

        public void Delete(int id)
        {

            _dao.Delete(id);
        }

        public List<ProductsClass> GetListByTID(int tid)
        {
            return _dao.GetListByTID(tid);
        }

        public bool Exists(int id)
        {

            return _dao.Exists(id);
        }

        public void Add(ProductsClass model)
        {

            _dao.Add(model);
        }

        public void Update(ProductsClass model)
        {

            _dao.Update(model);
        }

        public List<ProductsClass> GetAll(int? top, string strwhere, string orderby)
        {
            return _dao.GetAll(top, strwhere, orderby);
        }



    }
}